<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
			
			List<Apartments> list1 =(List<Apartments>)session.getAttribute("hehe");
			//String t = (String)session.getAttribute("Manage_Apartment");
//if(t!="active")
	//{response.sendRedirect("index.jsp");}
%>

<%@page import="java.util.List"%>
<%@page import="java.util.Iterator"%>
<%@page import="java.util.Calendar"%>
<%@page import="java.util.Date"%>
<%@page import="iwpl.project.dao.*"%>
<%@page import="iwpl.project.entities.*"%>
<%@page import="iwpl.project.servlet.*"%>
<%@page import="iwpl.project.interfaces.*"%>
<%@page import="iwpl.project.entitymanagerhelper.*"%>
<%@page import="iwpl.project.dao.ApartmentsDAO"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<center>
	<link rel="stylesheet" href="css/menu.css" type="text/css" />
	<link rel="stylesheet" href="css/CommonCSS.css" type="text/css" />
	<html>
		<head>
			<base href="<%=basePath%>">
			<title>Manage_Apartment.jsp</title>

			<script type="text/javascript">
	function Confirm(id) {
		var text = confirm("Are you sure ?");

		if (text == true) {
			//alert("Okey, Deleted !!!");
			location.href = "./servlet/Control_Apartment?delete=" + id;
		} else {
			alert("What ever !!!");
		}
	}
</script>


			<meta http-equiv="pragma" content="no-cache">
			<meta http-equiv="cache-control" content="no-cache">
			<meta http-equiv="expires" content="0">
			<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
			<meta http-equiv="description" content="This is my page">
			<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

		</head>

		<body>
			<table cellpadding="0" cellspacing="0">
				<tr>
					<td>
						
									<form id="form1" runat="server" method="post" action="./servlet/Control_Apartment" >
										<div align="center">
										</div>
										<table width="800" class="style1">
											<tr>
												<td class="style2" colspan="5" align="left">
													<div align="center"></div>
													<h2 align="Center">
														Apartment Manager
													</h2>
													<div align="left">
														<br />
													</div>
													<table width="743" border="0" height="144">
														<tbody>
															<tr>
																<td>
																	<input type="button" value="Insert" name="btnGoInsert"
														onClick="self.location='Insert_Apartment.jsp'" />
																</td>
																<td valign="top">
																	<br />
																</td>
																<td valign="top">
																	<br />
																</td>
																<td valign="top">
																	<br>
																</td>

															</tr>
															<tr>
																<td valign="top">
																	<br />
																</td>
																<td valign="top">
																	<br />
																</td>
																<td valign="top">
																	<br />
																</td>
																<td valign="top">
																	<br>
																</td>
															</tr>
															<tr>
																<td valign="top" style="width: 160px">
																	Filter By Area ID
																</td>
																<td valign="top">
																	<select name="cboSearchAreaID" style="width: 150px";>
																	<option></option>
																	<% 
																		ApartmentsDAO objDao= new ApartmentsDAO();
																		List<Apartments> lstOff = objDao.findAll();
																		for( Iterator it = lstOff.iterator(); it.hasNext(); ) {
																		Apartments apart = (Apartments)it.next();
																	 %> 		
																	 	
																	<option value="<%=apart.getAreas().getId()%>" label="<%=apart.getAreas().getId()%>">
																	<%=apart.getAreas().getId()%>
																	</option>
																	<%} %>
																	</select>
																</td>
																<td valign="top">

																	Filter By Apartment Number
																	<br>
																</td>
																<td valign="top">
																	<select name="cboAprtmentNumber" style="width: 150px";>
																	<option></option>
																	<% 
																		
																		for( Iterator it = lstOff.iterator(); it.hasNext(); ) {
																		Apartments apartNumber = (Apartments)it.next();
																	 %> 		
																	 	
																	<option value="<%=apartNumber.getApartmentNumber()%>" label="<%=apartNumber.getApartmentNumber()%>">
																	<%=apartNumber.getApartmentNumber()%> 
																	</option>
																	<%} %>
																	</select>
																</td>
															</tr>
															<tr>
																<td valign="top">
																	Filter By Floor Number
																</td>
																<td valign="top">
																
																	<select name="cboFloorNumber" style="width: 150px";>
																	<option></option>	
																	<% 
																		
																		for( Iterator it = lstOff.iterator(); it.hasNext(); ) {
																		Apartments apartFloor = (Apartments)it.next();
																	 %> 		
																	 	
																	<option value="<%=apartFloor.getFloorNumber()%>" label="<%=apartFloor.getFloorNumber()%>">
																	<%=apartFloor.getFloorNumber()%> 
																	</option>
																	<%} %>
																	</select>
																</td>
																<td valign="top">
																	Filter By Status
																	<br>
																</td>
																<td valign="top">
																	<select name="cboStatus" style="width: 150px"; >
																		<option></option>	
																	<option value="1">true</option>	
																	 	
																	<option value="0">false</option>
																	
																	</select>
																</td>
															</tr>
															<tr>
																<td valign="top">
																	<br>
																</td>
																<td valign="top">
																	<input type="submit" value="Search" name="btnSearch">
																</td>
																<td valign="top">
																	<br>
																</td>
																<td valign="top">
																	<br>
																</td>
															</tr>
														</tbody>
													</table>
													<table width="499" border="0" height="47">

														<tbody>



														</tbody>
													</table>
													<br />
												</td>
											</tr>
											<tr>
												<td colspan="5">
													<table>

													</table>
												</td>
											</tr>
											<table border="1">
												<tr bgcolor="5f9ff5">
													<td valign="top">
														&nbsp;No&nbsp;
														<br />
													</td>
													<td>
														&nbsp; Apartment ID&nbsp;
														<br />
													</td>
													<td>
														&nbsp; Area ID&nbsp;
														<br />
													</td>
													<td>
														&nbsp; Apartment Number &nbsp;
														<br />
													</td>
													<td>
														&nbsp;&nbsp; Floor Number&nbsp;&nbsp;
														<br />
													</td>
													<td>
														&nbsp; Status&nbsp;
														<br />
													</td>
													<td valign="top">
														&nbsp;Value&nbsp;
														<br />
													</td>
													<td>
														Update
														<br />
													</td>
													<td>
														Delete
														<br />
													</td>
												</tr>
												<%
													//ApartmentsDAO dao = new ApartmentsDAO();
													//List<Apartments> list = dao.findAll();
													
													//if(request.getParameter("cboSearchAreaID") != null )
													// {
													//list = dao.findByName(Integer.parseInt(request.getParameter("cboSearchAreaID")),Integer.parseInt(request.getParameter("cboAprtmentNumber")),Integer.parseInt(request.getParameter("cboFloorNumber")),Integer.parseInt(request.getParameter("cboStatus")));
														//}
														//else{
													//list = dao.findAll();}
													ApartmentsDAO dao = new ApartmentsDAO();
													
													
													List<Apartments> list=list1;
													
													if(list!=null)
													{	
													int i = 0;
													
													for (Iterator<Apartments> it = list.iterator(); it.hasNext();) {
														Apartments apart = (Apartments) it.next();
														i++;

														if (i % 2 != 0) {
															out.println("<tr bgcolor=\"#CCFFFF\"><td>");
														} else {
															out.println("<tr bgcolor=\"#99CCCC\"><td>");
														}
														out.println(i + "</td>");
														out.println("<td>" + apart.getId() + "</td>");
														out.println("<td>" + apart.getAreas().getId() + "</td>");

														out.println("<td>" + apart.getApartmentNumber() + "</td>");
														out.println("<td>" + apart.getFloorNumber() + "</td>");
														out.println("<td>" + apart.getStatus() + "</td>");
														out.println("<td>" + apart.getValue() + "</td>");

														//	out.println("<td>" + apart.getValue() + "</td>");
														//out.println("<td>" + rsq.getString("CountID") + "</td></tr>");
														//out.println("<td>" + rs.getString("Status") + "</td></tr>");
														out.println("<td><a href="
																+ "/DepartmentManage/Update_Apartment.jsp?id="
																+ apart.getId().toString() + " /><img src="
																+ "./images/Edit.jpg" + " /></td>");
														/*out.println("<td><a href=" + "./servlet/myservlet?delete="
																+ rs.getString("CategoryID") + " /><img src="
																+ "./Pics/Delete.jpg" + " /></td></tr>");*/
														//out.println("<td><img src=\"./Pics/Delete.jpg\" onclick =\"Confirm()\"/></td></tr>");
														out.println("<td><a href=javascript:Confirm('" + apart.getId()
																+ "') /><img src=" + "./images/Delete.jpg"
																+ " /></td></tr>");
													}
														list1.clear();															
														list.clear();
													}
													else													
													{
																									
													list = dao.findAll();
													}
												%>

											</table>
										</table>
										<div>

										</div>
									</form>
								
					</td>
				</tr>
			</table>


		</body>
	</html>
</center>
